package com.jswlw.schedule;

import com.jswlw.entity.biz.*;
import com.jswlw.service.biz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Component
public class TotalSchedule {
    @Autowired
    DevInfoService devInfoService;
    @Autowired
    DistributorService distributorService;
    @Autowired
    OrderInfoService orderInfoService;
    @Autowired
    BookInfoService bookInfoService;
    @Autowired
    FeedBackService feedBackService;
    @Autowired
    RepairInfoService repairInfoService;

    Map totalMap=new HashMap();



    @Scheduled(cron = "0 0/5 * * * ?")
    public void execute() {
        Map map=new HashMap<>();
        DevInfo devFilter = new DevInfo();
        List<DevInfo> devInfoList = devInfoService.queryList(devFilter);
        map.put("devCount", devInfoList.size());
        map.put("unBindDevCount", devInfoList.stream().filter(devInfo -> devInfo.getBindStatus().equals(0)).count());
        map.put("bindDevCount", devInfoList.stream().filter(devInfo -> devInfo.getBindStatus().equals(1)).count());

        Distributor distributorFilter = new Distributor();
        map.put("distributorCount", distributorService.queryList(distributorFilter).size());
        distributorFilter.setLevel(1);
        map.put("distributor1Count", distributorService.queryList(distributorFilter).size());
        distributorFilter.setLevel(2);
        map.put("distributor2Count", distributorService.queryList(distributorFilter).size());
        distributorFilter.setLevel(3);
        map.put("distributor3Count", distributorService.queryList(distributorFilter).size());

        OrderInfo orderFilter = new OrderInfo();
        List<OrderInfo> orderInfoList = orderInfoService.queryList(orderFilter);
        map.put("orderCount", orderInfoList.size());
        map.put("noPayOrderCount", orderInfoList.stream().filter(order -> order.getPayStatus().equals(0)).count());
        map.put("payOrderCount", orderInfoList.stream().filter(order -> order.getPayStatus().equals(1)).count());
        map.put("payOrderAmount", orderInfoList.stream().filter(order -> order.getPayStatus().equals(0)).mapToLong(order -> order.getAmount()).sum() * 0.01);

        BookInfo bookInfoFilter = new BookInfo();
        List<BookInfo> bookInfoList = bookInfoService.queryList(bookInfoFilter);
        map.put("bookInfoCount", bookInfoList.size());
        map.put("bookInfoNoDealCount", bookInfoList.stream().filter(bookInfo -> bookInfo.getStatus().equals(0)).collect(Collectors.toList()).size());
        map.put("bookInfoDealCount", bookInfoList.stream().filter(bookInfo -> bookInfo.getStatus().equals(1)).collect(Collectors.toList()).size());

        RepairInfo repairInfoFilter = new RepairInfo();
        List<RepairInfo> repairInfoList = repairInfoService.queryList(repairInfoFilter);
        map.put("repairInfoCount", repairInfoList.size());
        map.put("repairInfoNoDealCount", repairInfoList.stream().filter(bookInfo -> bookInfo.getStatus().equals(0)).collect(Collectors.toList()).size());
        map.put("repairInfoDealCount", repairInfoList.stream().filter(bookInfo -> bookInfo.getStatus().equals(1)).collect(Collectors.toList()).size());

        FeedBack feedBackFilter = new FeedBack();
        List<FeedBack> feedBackList = feedBackService.queryList(feedBackFilter);
        map.put("feedBackCount", feedBackList.size());
        map.put("feedBackNoDealCount", feedBackList.stream().filter(bookInfo -> bookInfo.getStatus().equals(0)).collect(Collectors.toList()).size());
        map.put("feedBackDealCount", feedBackList.stream().filter(bookInfo -> bookInfo.getStatus().equals(1)).collect(Collectors.toList()).size());
        totalMap.putAll(map);
    }

    public Map getTotalMap() {
        return totalMap;
    }

    public void setTotalMap(Map totalMap) {
        this.totalMap = totalMap;
    }
}
